package com.eos.control.action.activity;

import com.eos.business.service.SysActivityBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysActivty;
import com.eos.orm.mybatis.model.SysActivtySon;
import com.hf.utils.StringUtil;

public class DeleteSonActivityAction extends AbstractBaseAction {
	private static final long serialVersionUID = -1254847586774612344L;
	private String sonActivityId; //包含子活动ID和父活动ID, 格式: 11_1;

	public void setSonActivityId(String sonActivityId) {
		this.sonActivityId = sonActivityId;
	}

	@Override
	public String execute() {
		try {
			if(StringUtil.isEmpty(sonActivityId)){
				statusCode = "300";
				message = "参数错误, 删除子活动信息失败!";
			}else{
				SysActivityBusinessService sabs = new SysActivityBusinessService();
				String[] idArr = sonActivityId.split("_");
				SysActivtySon sas = new SysActivtySon();
				sas.setId(Integer.parseInt(idArr[0]));
				sas.setDealFlag(ConstantTool.DEAL_FLAG_FAIL);
				String exeStatus = sabs.updateSonActivityPKSelective(sas);
				if("SUCCESS".equals(exeStatus)){
					statusCode = "200";
					message = "删除子活动信息成功!";
					
					int activityId = Integer.parseInt(idArr[1]);
					SysActivty sa = sabs.getSysActivityPrimaryKey(activityId);
					Integer num = sa.getActivtySon();
					int sum = null != num && num.intValue() > 0 ? num.intValue() - 1 : 0;
					SysActivty s = new  SysActivty();
					s.setActivtySon(sum);
					s.setId(activityId);
					sabs.updateSysActivtyPKSelective(s);
				}else{
					statusCode = "300";
					message = "系统繁忙, 删除子活动信息失败!";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常, 删除子活动信息失败!";
		}
		return SUCCESS;
	}

}
